<template>
    <el-card>
           <el-form :model="queryParams" ref="queryParams" :inline="true" label-width="100px">
            <el-form-item label="键（Key）" prop="key">
                <el-input v-model="queryParams.key" placeholder="键（Key）" size="small"></el-input>
            </el-form-item>
            <el-form-item label="值（Value）" prop="value">
                <el-input v-model="queryParams.value" placeholder="值（Value）" size="small"></el-input>
            </el-form-item>
            <el-form-item >
                <el-button type="primary" icon="el-icon-search" size="small" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-delete" size="small" @click="resetQuery('queryParams')">清空</el-button>
            </el-form-item>
        </el-form>
        <el-table :data="tableData" border style="width: 100%" size="small">
            <el-table-column type="index" label="#" width="50"></el-table-column>
            <el-table-column label="键（Key）" prop="key"></el-table-column>
            <el-table-column label="值（Value）" prop="value"></el-table-column>
            <el-table-column label="数据类型" prop="type">
                <template slot-scope="{row}">
                    <span v-if="row.type === 1">布尔类型</span>
                    <span v-if="row.type === 2">字符串类型</span>
                    <span v-if="row.type === 3">数字型</span>
                    <span v-if="row.type === 4">JSON</span>
                </template>
            </el-table-column>
            <el-table-column label="修改时间" prop="createTime"></el-table-column>
            <el-table-column label="操作" width="100" align="center">
                <template slot-scope="scope">
                    <el-button size="mini" type="text" icon="el-icon-view" @click="handleView(scope.row)">查看</el-button>
                </template>
            </el-table-column>
        </el-table>
         <el-pagination
                v-show="total>0"
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                background
                :current-page="1"
                :page-sizes="[10, 20, 30, 40,50,100]"
                :page-size="10"
                layout="total, sizes, prev, pager, next, jumper"
                class="pagination-container"
                :total="total">
         </el-pagination>
        <el-dialog :title="title" :visible.sync="formVisible">
        <el-form :model="form" ref="form" :disabled="isView">
            <el-row :gutter="20">
                <el-col :span="12">
                    <el-form-item  prop="key" label="键(Key)：" :label-width="formLabelWidth" required>
                        <el-input v-model="form.key" autocomplete="off" size="mini" placeholder="请输入名称"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item  prop="value" label="值(Value)：" :label-width="formLabelWidth" required>
                        <el-input v-model="form.value" autocomplete="off" size="mini" placeholder="请输入值(Value)"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
                <el-row :gutter="20">
                <el-col :span="12">
                    <el-form-item  prop="type" label="数据类型：" :label-width="formLabelWidth" required>
                        <el-select v-model="form.type" placeholder="请选择数据类型" size="small" style="width: 100%">
                            <el-option :key="1" label="布尔型" :value="1"></el-option>
                            <el-option :key="2" label="字符串型" :value="2"></el-option>
                            <el-option :key="3" label="数字型" :value="3"></el-option>
                            <el-option :key="4" label="JSON" :value="4"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item  prop="value" label="修改时间" :label-width="formLabelWidth" required>
                        <el-input v-model="form.createTime" autocomplete="off" size="mini" placeholder="请输入值(Value)"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
        </el-dialog>
    </el-card>
</template>

<script>
import { getDictHistoryList } from '@/api/getway/dict.api.js'
    export default {
        data() {
            return {
                formVisible: false,
                title: '新增公共资源',
                formLabelWidth: "120px",
                form: {},
                isView: false,
                total: 0,
                tableData: [],
                queryParams: {
                    current: 1,
                    size: 10
                },
            }
        },
        mounted() {
            this.getList();
        },
        methods: {
            async getList() {
                const result = await getDictHistoryList(this.queryParams);
                if(result.code === 200) {
                    this.tableData = result.data.records;
                    this.total = result.data.total
                }
            },
             // 搜索
            handleQuery() {
                this.queryParams.current = 1;
                this.getList();
            },
            // 清空
            resetQuery(formName) {
                this.$refs[formName].resetFields();
                this.getList();
            },
            handleSizeChange(val) {
                this.queryParams.size = val;
                this.getList();
            },
            handleCurrentChange(val) {
                this.queryParams.current = val;
                this.getList();
            },
            handleView(row) {
                this.isView = true;
                this.form = row;
                this.formVisible = true;
                this.title = '查看公共资源';
            },
        },
    }
</script>

<style lang="scss" scoped>
.pagination-container {
    padding: 10px;
    text-align: right;
}
</style>